package cp3120.model;

import cp3120.dao.DAOFactory;
import cp3120.model.pricing.PricingStrategy;
import java.util.List;
import java.util.LinkedList;

/**
 * User: Rowan Spence
 * Date: 26/05/2009
 * Time: 8:31:16 PM
 */
public class Purchase {
    private List<Ticket> tickets = new LinkedList<Ticket>();
    private int purchaseID;
    private User user;
    private String purchaseDate;

    public Purchase() {};

    public Purchase(int purchaseID, User user, String purchaseDate) {
        this.purchaseID = purchaseID;
        this.user = user;
        this.purchaseDate = purchaseDate;
    }

    public void add(Ticket ticket) {
        tickets.add(ticket);
    }

    public void applyPricingStrategy() {
        // Make sure tickets are using base flight prices.

        for (Ticket t: tickets) {
            t.resetPrice();
        }

        List<PricingStrategy> pricingStrategys = DAOFactory.getPurchaseDAO().getPricingStrategys();

        for (PricingStrategy pricingStrategy: pricingStrategys) {
            pricingStrategy.execute(this);
        }
    }

    public void remove(Ticket ticket) {
        tickets.remove(ticket);
    }

    public int getPurchaseID() {
        return purchaseID;
    }

    public User getUser() {
        return user;
    }

    public String getPurchaseDate() {
        return purchaseDate;
    }

    public List<Ticket> getTickets() {
        return tickets;
    }

    public void setPurchaseID(int purchaseID) {
        this.purchaseID = purchaseID;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setPurchaseDate(String purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    public void setTickets(List<Ticket> tickets) {
        this.tickets = tickets;
    }

    public float getPrice() {
        float totalPrice = 0.0f;
        for (Ticket t: tickets) {
            totalPrice += t.getPrice();
        }
        return totalPrice;
    }

    public float getGST() {
        float totalGST = 0.0f;
        for (Ticket t: tickets) {
            totalGST += t.getGST();
        }
        return totalGST;
    }
}